const { src, dest, series, watch, parallel } = require('gulp');
const { clean } = require('./clean');
const { lint } = require('./lint');
const { compile } = require('./compile');
const imagemin = require('gulp-imagemin');
const cleanCSS = require('gulp-clean-css');
const uglify = require('gulp-uglify');
const pipeline = require('readable-stream').pipeline;

function buildImages() {
    return src('src/assets/images/*')
        .pipe(imagemin())
        .pipe(dest('dist/assets/images/'));
}

function buildFonts() {
    return src('src/assets/fonts/**')
        .pipe(imagemin())
        .pipe(dest('dist/assets/fonts/'));
}

function buildHtml() {
    return src('temp/**/*.html')
        .pipe(dest('dist/'));
}

function buildStyles() {
    return src('temp/**/*.css')
        .pipe(cleanCSS())
        .pipe(dest('dist/'));
}

function buildScripts() {
    return pipeline(
        src('temp/**/*.js'),
        uglify(),
        dest('dist/')
    );
}

module.exports = series(
    clean,
    lint,
    compile,
    parallel(buildImages, buildFonts, buildHtml, buildStyles, buildScripts)
)
